#!/usr/bin/env sh

deactivate() {
  export PS1=$_OLD_PS1
  export PATH=$_OLD_PATH
  unset -v _OLD_PS1 _OLD_PATH

  export JAVA_HOME=$_OLD_JAVA_HOME
  unset -v _OLD_JAVA_HOME

  unset -f deactivate
}

activate() {
  local _DIRNAME=${PWD##*/}

  if ! grep -qi $_DIRNAME <<< $PS1; then
    _OLD_PS1=$PS1
    _OLD_PATH=$PATH
    export PS1="($_DIRNAME) $PS1"
    export PATH="/usr/lib64/openjdk-17/bin/:$PATH"

    _OLD_JAVA_HOME=$JAVA_HOME
    export JAVA_HOME="/usr/lib64/openjdk-17/"
    unset -f activate
  fi
}

activate
